package vue;

import controleur.ControllerParametrageSimulation;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;

import controleur.ControllerSimulation;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class SimuListener implements ActionListener, WindowListener {

	VueSimulation vue;

	public SimuListener(VueSimulation vs) {
		vue = vs;
	}

	@Override
	public void windowOpened(WindowEvent e) {
	}

	@Override
	public void windowClosing(WindowEvent e) {
		this.vue.getC().stop();
	}

	@Override
	public void windowClosed(WindowEvent e) {
	}

	@Override
	public void windowIconified(WindowEvent e) {
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
	}

	@Override
	public void windowActivated(WindowEvent e) {
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("play")) {
			vue.getStop().setEnabled(true);
			vue.getC().start();
		} else if (e.getActionCommand().equals("pause")) {
			vue.getC().pause();
		} else if (e.getActionCommand().equals("stop")) {
			int rep2 = JOptionPane.showConfirmDialog(null, "Voulez-vous consulter les statistiques avant de quitter ?", "Confirmation", JOptionPane.YES_NO_OPTION);
			if (rep2 == 0) {
				new VueStatistique(vue.getList_nb_fourmis(),vue.getList_nb_fourmis_moyen(),vue.getList_quantite_nourriture());
			}else{
				vue.getPlay().setEnabled(false);
				vue.getPause().setEnabled(false);
				vue.getStop().setEnabled(false);
				vue.getC().stop();
			}

		}else if (e.getActionCommand().equals("stats")) {
			new VueStatistique(vue.getList_nb_fourmis(),vue.getList_nb_fourmis_moyen(),vue.getList_quantite_nourriture());

		}else if (e.getActionCommand().equals("avance")) {
			if(((JCheckBox)e.getSource()).isSelected()){
				vue.getC().setTimeTick("rapide");
			}else{
				vue.getC().setTimeTick("lent");
			}

		}

	}

}
